package team3132.utils;

import edu.wpi.first.wpilibj.Timer;

/**
 * Logs output from the robot, this class makes it easy to find where the output is coming from.
 */
public class Trace {

  String className;
  boolean enabled = true;

  public Trace(Object objectPassed) {
    //Gets the class
    Class classPassed = (Class) objectPassed.getClass();
    //Gets the whole name of the class with the package
    String packageWithClass = classPassed.getName();
    //Trims off the package part
    this.className = packageWithClass.substring(packageWithClass.lastIndexOf(46) + 1);
  }

  public Trace(String overrideName) {
    this.className = overrideName;
  }

  public void trace(String message) {
    if (enabled) {
      double time = Timer.getFPGATimestamp();
      SynchronizedOutput.get().println(className + "[" + time + "]: " + message);
    }
  }

  public void traceOff() {
    enabled = false;
  }

  public void traceOn() {
    enabled = true;
  }
}
